#Makefile for pirateAcorn
#Author Matt Weir

EXTRA_CFLAGS += $(DEBFLAGS) -I$(LDDINC)

ifneq ($(KERNELRELEASE),)
# call from kernel build system


obj-m	:=  pirateAcorn.o

else

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD       := $(shell pwd)

default:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
	gcc ./pa_ioc_startread.c -o ./examples/pa_ioc_startread
	gcc ./pa_ioc_stopread.c -o ./examples/pa_ioc_stopread
	gcc ./test_reader_writer.c -o ./examples/test_reader_writer
	gcc ./pa_ioc_startwrite.c -o ./examples/pa_ioc_startwrite
	gcc ./pa_ioc_stopwrite.c -o ./examples/pa_ioc_stopwrite
	gcc ./pa_ioc_setlogger.c -o ./examples/pa_ioc_setlogger
	gcc ./pa_ioc_setsingle.c -o ./examples/pa_ioc_setsingle
	gcc ./pa_ioc_logall.c -o ./examples/pa_ioc_logall

modules:
#I can do without the verbose output, feel free to uncomment for debugging though
#	echo $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
	$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
endif



clean:
	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

depend .depend dep:
	$(CC) $(CFLAGS) -M *.c > .depend

load:
	sudo ./pa_load
unload:
	sudo ./pa_unload
reload:
	sudo ./pa_unload
	sudo ./pa_load

ifeq (.depend,$(wildcard .depend))
include .depend
endif
